CC = gcc
CFLAGS = -Os
INCLUDE = -I/usr/include/cairo \
		-I/usr/include/atk-1.0 \
		-I/usr/include/gtk-3.0 \
		-I/usr/include/libpng16 \
		-I/usr/include/pixman-1 \
		-I/usr/include/glib-2.0 \
		-I/usr/include/dbus-1.0 \
		-I/usr/include/harfbuzz \
		-I/usr/include/freetype2 \
		-I/usr/include/pango-1.0 \
		-I/usr/include/at-spi-2.0 \
		-I/usr/include/gio-unix-2.0 \
		-I/usr/include/gdk-pixbuf-2.0 \
		-I/usr/include/at-spi2-atk/2.0 \
		-I/usr/lib/x86_64-linux-gnu/dbus-1.0/include \
		-I/usr/lib/x86_64-linux-gnu/glib-2.0/include
LDFLAGS = -lm \
		-lgtk-3 \
		-lgdk-3 \
		-lcairo \
		-pthread \
		-latk-1.0 \
		-lgio-2.0 \
		-lglib-2.0 \
		-lpango-1.0 \
		-lgobject-2.0 \
		-lcairo-gobject \
		-lgdk_pixbuf-2.0 \
		-lpangocairo-1.0

SOURCES = gtk_ui.c main.c particle.c thread.c
S_OBJECTS = $(SOURCES:.c=.o)
OBJECTS = $(addprefix build/, $(SOURCES:.c=.o))
EXECUTABLE = particles

all: check_gtk build $(EXECUTABLE)

check_gtk:
	@if ! pkg-config --exists gtk+-3.0; then \
		echo "GTK is not installed. Installing GTK..."; \
		sudo apt-get install -y libgtk-3-dev build-essential libglib2.0-dev; \
	fi

build:
	@mkdir -p build

$(EXECUTABLE): $(OBJECTS)
	@$(CC) -o $@ $^ $(LDFLAGS)
	@echo "$(S_OBJECTS) \t--> $@"

build/%.o: %.c include.h
	@$(CC) -c $(INCLUDE) $(CFLAGS) $< -o $@
	@echo "$< \t--> $@"

clean:
	rm -rf build $(EXECUTABLE)

.PHONY: all clean
